
/*
 * This rice_besseli_funs_c.cpp is a MEX-file for MATLAB.
 * Created by Dirk Poot, Erasmus Medical Center 
 * Build with: (add -g for debugging (add -O for optimizations while debugging); -v for verbose mode )
 * mex rice_besseli_funs_c.cpp -I".\Tools\supportingfiles\" -g
 *
 * On Linux  (cluster):
 * mex rice_besseli_funs_c.cpp -I"./Tools/supportingfiles/" -g CXXFLAGS="\$CXXFLAGS -mssse3 -mtune=core2"
 */

#include "mex.h"
#include <cmath>
#include "emm_wrap.cpp"
#include "tempSpaceManaging.cpp"
#include <iterator>
#include <limits>
#include "fixed_len_bsearch.cpp"


#define MAXELPERBLOCK 1024
const int numPolynomes = 51;
const int polyorder = 8;
const int numTableElements= numPolynomes*polyorder;
const int cutoffbinidx = 29;
ALIGN_VEC const int32_t tablelimits[(numPolynomes+1)] = { 0x00000000, 0x3D234000, 0x3DF52100, 0x3E46F840, 0x3E88D9C0, 0x3EAE3760, 0x3ED3F820, 0x3EFA7D80, 0x3F1114F0, 0x3F25BF00, 0x3F3BAE90, 0x3F53E2E0, 0x3F6EB370, 0x3F8420E0, 0x3F904818, 0x3F9C4C20, 0x3FA86090, 0x3FB4A9D0, 0x3FC148E0, 0x3FCE6250, 0x3FDC26A8, 0x3FEAEC50, 0x3FFB7D70, 0x4006CA38, 0x400F8380, 0x4017F658, 0x40206320, 0x4028EA7C, 0x4031A278, 0x403A9D94, 0x404583FA, 0x405179C2, 0x405EEB72, 0x406F0272, 0x40814E81, 0x408AA95C, 0x40949480, 0x409F90A0, 0x40AC36AB, 0x40BC83F5, 0x40CCB854, 0x40DE50FE, 0x40F315AB, 0x4107C94D, 0x41166FF1, 0x41286BAB, 0x4143C1F7, 0x416405C7, 0x419178AD, 0x41C85F71, 0x42394B24, 0x461C4000 };
ALIGN_VEC const int32_t origins[(numPolynomes)*2] = { 0x00000000,0x00000000  , 0x00000000,0x3FB46C10  , 0x00000000,0x3FC4188C  , 0x00000000,0x3FCD8ABC  , 0x00000000,0x3FD37112  , 0x00000000,0x3FD822F8  , 0x00000000,0x3FDCE75A  , 0x00000000,0x3FE0E53B  , 0x00000000,0x3FE36D3F  , 0x00000000,0x3FE616D9  , 0x00000000,0x3FE8F917  , 0x00000000,0x3FEC2965  , 0x00000000,0x3FEF6F53  , 0x80000000,0x3FF1468F  , 0x80000000,0x3FF2C943  , 0x00000000,0x3FF44ACB  , 0x00000000,0x3FF5D0A6  , 0x00000000,0x3FF75F2B  , 0x00000000,0x3FF8FAB3  , 0x80000000,0x3FFAA88F  , 0x80000000,0x3FFC712F  , 0x00000000,0x3FFE669C  , 0x00000000,0x4000488F  , 0x80000000,0x400164DB  , 0x80000000,0x4002779D  , 0x80000000,0x40038597  , 0xC0000000,0x400494D9  , 0x40000000,0x4005A8CF  , 0xC0000000,0x4006C400  , 0x00000000,0x3FD55818  , 0x00000000,0x3FD42546  , 0x00000000,0x3FD2F6C6  , 0x00000000,0x3FD1C180  , 0x00000000,0x3FD07CE4  , 0x00000000,0x3FCE9BAC  , 0x00000000,0x3FCC8DB8  , 0x00000000,0x3FCA9E64  , 0x00000000,0x3FC8BA24  , 0x00000000,0x3FC6C18C  , 0x00000000,0x3FC4DE24  , 0x00000000,0x3FC3374C  , 0x00000000,0x3FC1A31C  , 0x00000000,0x3FBFEEC0  , 0x00000000,0x3FBCB238  , 0x00000000,0x3FB9C610  , 0x00000000,0x3FB69F38  , 0x00000000,0x3FB37188  , 0x00000000,0x3FB00550  , 0x00000000,0x3FA84CA0  , 0x00000000,0x3F9F7EA0  , 0x00000000,0x3F861B00   };
ALIGN_VEC const int32_t fun1[(numTableElements)*2] = { 0x83F9A18C,0xBEF2B2F5  , 0x01B2D9A6,0x3F5C73A4  , 0xD6CECCF4,0xBE2E68C0  , 0xFFD93789,0xBF8FFFFF  , 0x00000000,0x00000000  , 0x00000000,0x3FD00000  , 0x00000000,0xBFF00000  , 0x00000000,0x00000000  , 0x0E1CB933,0xBF2276F9  , 0x53A6B55C,0x3F5BC8BE  , 0x90599422,0x3F4B0596  , 0x7B01251B,0xBF8FA971  , 0x028A22DA,0xBF74599F  , 0x14043DDD,0x3FCFEC7C  , 0x78921013,0xBFEEB981  , 0x948A3258,0xBFB403D6  , 0x86650227,0xBF317E5D  , 0x8682EC7B,0x3F59F802  , 0x58766F73,0x3F5A030F  , 0xEE97274D,0xBF8EB466  , 0x952A8007,0xBF83D2B8  , 0x65C8A729,0x3FCFB4CB  , 0xA6AAEB67,0xBFED7EE7  , 0x4D619DFD,0xBFC34EEF  , 0x4B7AB08B,0xBF3839E4  , 0x985DC74F,0x3F5742C8  , 0x583F3AAC,0x3F627928  , 0xF7FAA0DF,0xBF8D3F86  , 0x0D7CC4C2,0xBF8CAF2B  , 0x25BA143A,0x3FCF5EC1  , 0xB30D550C,0xBFEC54E5  , 0xD3031368,0xBFCBD7D0  , 0xF5F0AB9B,0xBF3D60B4  , 0x6D65941A,0x3F53D21E  , 0x0D03DA08,0x3F6733E5  , 0xE22A6C8B,0xBF8B576A  , 0x3479C6DB,0xBF927A2F  , 0xD34C7133,0x3FCEEB9F  , 0x252079D2,0xBFEB31DE  , 0xCF87137B,0xBFD1F93F  , 0xEE2E3275,0xBF40672F  , 0x155959F8,0x3F4F9ECC  , 0x54DE592B,0x3F6B21E3  , 0x0F1AE188,0xBF8906E4  , 0x02AAE820,0xBF9652C6  , 0x21265CA0,0x3FCE5BC2  , 0x019181B3,0xBFEA1216  , 0xE80ACC9C,0xBFD5E17D  , 0x1F040E68,0xBF4133C4  , 0x093B4CBA,0x3F46D1B0  , 0x201011B7,0x3F6E2D8B  , 0x20FFBDE4,0xBF8659EC  , 0xD30E5027,0xBF99DB1A  , 0x7A4421CA,0x3FCDAF43  , 0x6BC5C0C9,0xBFE8F3C6  , 0x56C6FE88,0xBFD9AE57  , 0x268111FE,0xBF411291  , 0xE57FC9EB,0x3F3B3CCA  , 0xAA54B162,0x3F7021CA  , 0xE7C4EC43,0xBF835CDD  , 0x1A57DFE0,0xBF9D0B34  , 0xF7983F3E,0x3FCCE5C1  , 0xC0203E31,0xBFE7D566  , 0xFAE69972,0xBFDD67EF  , 0xB35DF40B,0xBF400AD8  , 0x0ED7E7EB,0x3F21A768  , 0xC769FD63,0x3F70A9EC  , 0x9AE9845F,0xBF801C65  , 0xE3B5E30D,0xBF9FD9EA  , 0x34654AC5,0x3FCBFE37  , 0xDDEDFC49,0xBFE6B550  , 0xF3D45096,0xBFE08B27  , 0x7A3FC8DD,0xBF3C59AC  , 0x899A5DA9,0xBF21AB7F  , 0x2A39D142,0x3F70A849  , 0xD4624FAF,0xBF79458A  , 0x0C4684F8,0xBFA11F1C  , 0xA91D003C,0x3FCAF5DD  , 0x34B303DD,0xBFE5909F  , 0x23F5BE19,0xBFE26297  , 0xDDEE65F4,0xBF3712DE  , 0x0E7A1F09,0xBF391920  , 0x01D038C9,0x3F7012D7  , 0x2AB5BBD1,0xBF71E07D  , 0x46DFD835,0xBFA217B7  , 0xDC8A1DA8,0x3FC9C4BC  , 0xA163A52E,0xBFE46071  , 0x1EEE34DF,0xBFE44649  , 0xD2718D6A,0xBF30863C  , 0x087610F3,0xBF4375C8  , 0x0338C384,0x3F6DB932  , 0x8147912B,0xBF644C43  , 0xDE0A3187,0xBFA2C9CD  , 0x5FFC186E,0x3FC86351  , 0x935496CA,0xBFE32085  , 0x2207A029,0xBFE63E00  , 0xD91752FA,0xBF23A5C9  , 0xFAEBFC53,0xBF482AD0  , 0x85A1D5C5,0x3F6A57B1  , 0xCFBAC4CD,0xBF47B886  , 0x3F64789F,0xBFA31EB5  , 0x08917FCA,0x3FC6EE7A  , 0xA3F21B6B,0xBFE1EAB9  , 0x5B3E7297,0xBFE822D7  , 0x5D065C40,0xBF103D45  , 0x5B05D3F3,0xBF4A8323  , 0x76E3E7B0,0x3F669D48  , 0x175C5C6B,0x3F48032F  , 0x609CBA75,0xBFA31D89  , 0x07936D84,0x3FC5888E  , 0xB874D010,0xBFE0D595  , 0xC49004B9,0xBFE9D3E4  , 0xE403E9D2,0x3EE361C4  , 0xE7272256,0xBF4B0E52  , 0xC810B38F,0x3F62CD1B  , 0x3BB7E863,0x3F5F8FF9  , 0x015A8499,0xBFA2DAD1  , 0xC5C320ED,0x3FC43011  , 0x454727C9,0xBFDFB307  , 0xFD31F9B2,0xBFEB5EBB  , 0x8AFB6197,0x3F10CC02  , 0x295CB346,0xBF4A3C40  , 0xCA54747A,0x3F5E0C31  , 0x14A5E2E4,0x3F67BC65  , 0x5E0C92D5,0xBFA262E6  , 0x744F8A58,0x3FC2DF48  , 0x30A944BF,0xBFDDDC82  , 0xF5417354,0xBFECD171  , 0x380664DC,0x3F1AFE48  , 0x8813C245,0xBF486206  , 0x65D4DB01,0x3F56CC6D  , 0xE8BDE20D,0x3F6E0341  , 0xADCBCADA,0xBFA1BE51  , 0xEFA9FECF,0x3FC194ED  , 0xE1A18630,0xBFDC207B  , 0x2DFDB572,0xBFEE328E  , 0xE49A10C2,0x3F20A5A6  , 0x315AEC9D,0xBF45CA24  , 0xE9A9F2DE,0x3F500BAC  , 0x25D46970,0x3F715C5A  , 0xB007E59D,0xBFA0F3EB  , 0x864ED7CA,0x3FC050AD  , 0xF02AA90B,0xBFDA7A75  , 0x7937A5CE,0xBFEF8672  , 0x0B362DDB,0x3F2210AF  , 0x07A5E7F9,0xBF42B6CE  , 0x53B56BA9,0x3F43DE78  , 0x229E735F,0x3F72FB81  , 0xA581D566,0xBFA00967  , 0x4B6B3D81,0x3FBE24B5  , 0x81B029BB,0xBFD8E6F6  , 0x82B59314,0xBFF06859  , 0xC98C6496,0x3F2203FD  , 0x402D6C2C,0xBF3EC31E  , 0x8B2F8295,0x3F32452F  , 0xC39B9663,0x3F73EC12  , 0x1AC595DA,0xBF9E069F  , 0x5FE1CF1E,0x3FBBB2E6  , 0x3035E1F5,0xBFD762A4  , 0x006E3E94,0xBFF10A71  , 0x5EBD4F30,0x3F20C7AF  , 0x65CDA95A,0xBF37F1AB  , 0xC328CA59,0x3E7117A0  , 0x33664DF4,0x3F743A2B  , 0x18EFFDD8,0xBF9BC832  , 0xD79C6D8E,0x3FB9482B  , 0xFEFA3289,0xBFD5E8DB  , 0x15FA1A02,0xBFF1ABF2  , 0xD6CA6895,0x3F1D351A  , 0xF862CFE3,0xBF3133BC  , 0xBDD19FB4,0xBF2E163A  , 0xC7C87CBA,0x3F73EC7A  , 0x50476936,0xBF99518C  , 0x57D1C814,0x3FB6D833  , 0xA3CC0EF9,0xBFD47018  , 0x397DF024,0xBFF251BD  , 0x84C971DE,0x3F1797A2  , 0xA0EAEE2D,0xBF25E30A  , 0x4F4BDE69,0xBF3A5FD3  , 0x5D5E9427,0x3F73079B  , 0x7D963C28,0xBF96AD2A  , 0x30210D28,0x3FB468B5  , 0x20D51301,0xBFD2F9BA  , 0xCD1F8755,0xBFF2FC5C  , 0x5848EB29,0x3F11E6DA  , 0x800D37A0,0xBF17A497  , 0x7D4137F0,0xBF40A4B9  , 0xD840762F,0x3F71B872  , 0x1AFD2D86,0xBF941F47  , 0xA2793A70,0x3FB22EC1  , 0x7558F531,0xBFD1A342  , 0xE8D71570,0xBFF39EE3  , 0x327719A8,0x3F0A0144  , 0xA6068C3E,0xBF025F6B  , 0x6336F482,0xBF424099  , 0xBD941D3D,0x3F703F52  , 0xCCFFD1E0,0xBF91D795  , 0x81389327,0x3FB0463A  , 0xEFA70917,0xBFD07BBB  , 0x96609E65,0xBFF43148  , 0xBC7F3225,0x3F01F9B8  , 0xD33ED17D,0x3ECCB476  , 0x92CCCECD,0xBF42A0D9  , 0xCCADF5D7,0x3F6D7143  , 0x789B76B8,0xBF8F99E6  , 0x96025B16,0x3FAD39CC  , 0xFCE3CDA4,0xBFCEEEDB  , 0xBBBAD1D0,0xBFF4B7FB  , 0x0EF205CB,0x3EF72931  , 0x34A564AC,0x3EFEBDC6  , 0x25BE4CC1,0xBF422CC5  , 0xE679C802,0x3F6A62F3  , 0xC7C2AB07,0xBF8BE79B  , 0x58BDDE49,0x3FAA4606  , 0x611AC6CA,0xBFCD18EB  , 0x9941A324,0xBFF53721  , 0x2FB01276,0x3EEAA5FC  , 0x178789AD,0x3F07DB88  , 0xCD2DFE2F,0xBF412984  , 0x65920986,0x3F676793  , 0xDC4966A0,0xBF888D54  , 0x1B0323E2,0x3FA7A055  , 0x92A4D3D4,0xBFCB6B15  , 0x31A40AC1,0xBFF5B0E9  , 0xA1B20953,0x3ED8406E  , 0x0C87D8DD,0x3F0C71FA  , 0x7EFAE3F4,0xBF3F9423  , 0x4C1ED69C,0x3F648DAB  , 0xB4792AF3,0xBF8583FE  , 0xB94F28F3,0x3FA53DAB  , 0xB670F4AC,0xBFC9DE7B  , 0xE3EBE8E7,0xBFF626BE  , 0xFC7DD8EA,0xC02C56C3  , 0x61E30AEE,0xC009BB63  , 0xBD12BF85,0x400ACBB1  , 0xF0B3AF0F,0xBFE17479  , 0xBF6486EB,0xBFDDA8A7  , 0x15F51948,0x3FBD0D2B  , 0x0E6E6625,0x3FCAE6DF  , 0x37B269F4,0xBFEBB0F4  , 0xA1A4B622,0xC0390564  , 0xA15A9744,0xBFE59134  , 0x3085336E,0x400CA98E  , 0xC465454A,0xBFEBE960  , 0x2154EFCC,0xBFDA44F4  , 0xE605E592,0x3FC1AEB6  , 0xAE0AB347,0x3FCA4C28  , 0x8FDC2A9C,0xBFEBD0D8  , 0xAC1778F3,0xC042A246  , 0xF894D5A0,0x400AC4A9  , 0xCC783CF6,0x400B9BAD  , 0x94D3A39B,0xBFF3348B  , 0x301B1254,0xBFD55DDA  , 0x97178891,0x3FC455D9  , 0x8E584967,0x3FC99809  , 0x9B65D77E,0xBFEBEF83  , 0x431FA4BF,0xC0481BE6  , 0x5F76BF19,0x402213FF  , 0xE8C749B2,0x40061E78  , 0xDF63C156,0xBFF7FADE  , 0xE142A9A4,0xBFCDA365  , 0x1C4F4C61,0x3FC665F0  , 0x2279AC0A,0x3FC8C8EF  , 0x0741BA5A,0xBFEC0DF4  , 0x5B3AF735,0xC0497C57  , 0xD89B2CA9,0x40301311  , 0xCF0AE981,0x3FF46CDB  , 0x9CCA95F4,0xBFFB4B47  , 0xC83370AD,0xBFBA8501  , 0x69DE25F7,0x3FC7AEFD  , 0xDF09F42E,0x3FC7DE61  , 0x1CC842CE,0xBFEC2CCE  , 0x2660D974,0xC041C7C8  , 0x41A765A8,0x4035ED0C  , 0xD42DF66A,0xBFEB44D7  , 0xCC8F136B,0xBFFBB069  , 0x729E6ED1,0x3F99588E  , 0xED183C74,0x3FC7F6F4  , 0x447D1E74,0x3FC6FC09  , 0xEA733582,0xBFEC4889  , 0x84B9BA79,0xBFB26848  , 0x1CE66B37,0x40382549  , 0x37E9ACCF,0xC008D8FB  , 0x205AEC5F,0xBFF92BE0  , 0x3B18DBB3,0x3FC0DE24  , 0x88AFA639,0x3FC77A23  , 0x1A32A1F5,0x3FC638A5  , 0x9A67EF63,0xBFEC5FC1  , 0x926DC5A4,0x404B0AEC  , 0xA95F5645,0x403572C1  , 0xEEAE9EEB,0xC014E2EA  , 0x28F41329,0xBFF41CA6  , 0xAC1D16B1,0x3FCBEC6A  , 0xBEC51D29,0x3FC673C5  , 0xFA849416,0x3FC58695  , 0x3DE6BA02,0xBFEC74EA  , 0x1DC9C8B8,0x405D76B8  , 0x7C5C87B8,0x40292416  , 0xCF1C3D21,0xC01B22DA  , 0x1ABA3E00,0xBFE9E007  , 0x7AB47F4D,0x3FD1E7D9  , 0xBAAC1D31,0x3FC506DF  , 0xEDF6B931,0x3FC4E1DF  , 0x6A2A5F0E,0xBFEC88F7  , 0x18D179F4,0x40652580  , 0xB3067615,0xC009B8F4  , 0x20FA1D68,0xC01D0E2F  , 0x15610BC4,0xBFD08946  , 0x7530F398,0x3FD40567  , 0xD254FB47,0x3FC3420B  , 0x0DF92C60,0x3FC442F0  , 0x7E39DF0C,0xBFEC9D3C  , 0x55082A29,0x40647714  , 0x0F51EFFD,0xC0350928  , 0xB03D7FA4,0xC018BF46  , 0x5B4DA3EE,0x3FCFADF3  , 0x94965A3C,0x3FD40442  , 0xB093A3B6,0x3FC178CD  , 0x47FC0E3D,0x3FC3B839  , 0x3551B2B8,0xBFECB01B  , 0x0854E6B8,0x40560457  , 0x0F25C93E,0xC04077B0  , 0x336429CB,0xC01031DD  , 0xB6FD64B4,0x3FE2A598  , 0x7DDCB02F,0x3FD29B72  , 0xC9424AD0,0x3FBFF061  , 0xC8D5FDC8,0x3FC349CF  , 0x176EC55D,0xBFECC036  , 0x165F7604,0xC042FDE2  , 0x7C2392DE,0xC041AAC9  , 0xCD8749C2,0xBFF729AC  , 0xE6B0EC89,0x3FE819C6  , 0xEA301A2C,0x3FD074A4  , 0xA12037E5,0x3FBD565E  , 0x2DC60430,0x3FC2E926  , 0x727043E1,0xBFECCF49  , 0xCDEEEED5,0xC064D8CA  , 0xE38F94C8,0xC039924E  , 0x9DDEE9D0,0x3FF05F57  , 0x40185ABE,0x3FE868D1  , 0x745CFC86,0x3FCBC14D  , 0xE742C059,0x3FBAF616  , 0x317F8042,0x3FC28B32  , 0x09223A73,0xBFECDEEE  , 0x13A1DCDC,0xC068D4AE  , 0xECA2E7A2,0xC020FAB8  , 0x788B36BC,0x4002AF96  , 0x35B5EA31,0x3FE4CA3B  , 0x09E54B91,0x3FC72387  , 0x79D4E2F0,0x3FB90924  , 0xD90A1D9C,0x3FC23725  , 0xA11D8700,0xBFECEDCC  , 0x3BB9596A,0xC05E0D29  , 0x768A7E35,0x40132BB8  , 0x0C61D2AF,0x400360C6  , 0x2B44567B,0x3FE04DEB  , 0x5DFFE860,0x3FC3BFB4  , 0xF4CF5E2E,0x3FB79254  , 0x63F3FFDF,0x3FC1F02D  , 0x7022B84A,0xBFECFB01  , 0x82E01C5A,0xBFEC1075  , 0x68F00B92,0x40238F0B  , 0xD4F45C81,0x3FFD01D5  , 0xF11AC1F6,0x3FD82569  , 0xE8A37AB6,0x3FC0F95A  , 0x41C8A834,0x3FB6386D  , 0xA59D9B46,0x3FC1A811  , 0x1478E8C0,0xBFED0907  , 0x1EA1D382,0x4046EEFD  , 0xE0F24E55,0x401C94B7  , 0x3C95E8B1,0x3FF278C5  , 0xD004C3BF,0x3FD2525D  , 0xA98CCC16,0x3FBDC605  , 0xD18C782D,0x3FB50989  , 0x0D988FF6,0x3FC1635D  , 0x41905056,0xBFED16F3  , 0xE80A000C,0x4039F6A5  , 0xFF3D0426,0x400CF078  , 0xBBDFC202,0x3FE79B3A  , 0xE2FD313C,0x3FCCC0CD  , 0x14DAC885,0x3FBA4EC3  , 0xA3A0B61C,0x3FB3EA54  , 0x762C2CCA,0x3FC11D51  , 0xF7AA8BFE,0xBFED25B5  , 0xC37E5861,0x40233D2E  , 0xDFCD82AD,0x3FFE85FD  , 0xBE628169,0x3FE00B06  , 0xD46C06A1,0x3FC6E0EF  , 0x05562242,0x3FB7351D  , 0xBB8A7B41,0x3FB2CB7F  , 0x1E8A8DA4,0x3FC0D270  , 0x81F529F7,0xBFED3621  , 0xC0A8D34F,0x40121B50  , 0x23171DFD,0x3FF226BA  , 0xAF7A59B5,0x3FD6AC1F  , 0xC4FE77F2,0x3FC25F8D  , 0x31FCBEC6,0x3FB477FE  , 0x5CE1DF85,0x3FB1B400  , 0x36CB880C,0x3FC08474  , 0xFE2397E7,0xBFED47F2  , 0x3D14146C,0x4002215F  , 0x1B3C3482,0x3FE5E3C6  , 0x1EE29951,0x3FCFD7CC  , 0x66FE10A7,0x3FBD27C5  , 0x36521FB7,0x3FB1DAFA  , 0xF962B38B,0x3FB08EFD  , 0x49D62A28,0x3FC02CF9  , 0xD6783506,0xBFED5CD4   };
ALIGN_VEC const int32_t fun2[(numTableElements)*2] = { 0x7E156554,0xBF5D4CF7  , 0x401FCFD5,0xBE789F61  , 0x870D9AA2,0x3F855555  , 0x4AD80AD7,0xBDA08DB5  , 0xFFFFFC98,0xBFAFFFFF  , 0x00000000,0x00000000  , 0x00000000,0x3FE00000  , 0x00000000,0x00000000  , 0x2913D243,0xBF5C2B45  , 0x970799C5,0xBF502774  , 0x4F8811E6,0x3F84D8B6  , 0x052479F6,0x3F70E37E  , 0x92712BD7,0xBFAFA971  , 0x83CDEA21,0xBF8E866E  , 0x14045C76,0x3FDFEC7C  , 0x76DEFECC,0x3FA467E8  , 0x70EF092F,0xBF58FF8B  , 0x8B30FDF1,0xBF5E9C17  , 0x70CE757C,0x3F837BAD  , 0x885C9070,0x3F8041E9  , 0xFE7599EB,0xBFAEB466  , 0xDFBEF3CC,0xBF9DBC14  , 0x65C8B941,0x3FDFB4CB  , 0xCAA8A4CA,0x3FB408C2  , 0x17E74542,0xBF546468  , 0xDD87059F,0xBF6531FB  , 0x19F76ED4,0x3F817364  , 0x5BFF9059,0x3F871772  , 0x03D38BD0,0xBFAD3F87  , 0x4A1D1BBB,0xBFA58360  , 0x25BA2126,0x3FDF5EC1  , 0x679557A1,0x3FBD58D2  , 0xB171E10F,0xBF4D8873  , 0x5B2C73FC,0xBF69B3D7  , 0xDAEA0756,0x3F7DBD10  , 0x3B128EBE,0x3F8D00DE  , 0xEABE9DED,0xBFAB576A  , 0xCEB61F8F,0xBFABB746  , 0xD34C7A8E,0x3FDEEB9F  , 0x6B7E18B7,0x3FC33887  , 0xD761D1D9,0xBF411BB7  , 0xE42D4212,0xBF6CB3BE  , 0xD07F7CB5,0x3F77B836  , 0x09766BC9,0x3F90F52E  , 0x1448A7D2,0xBFA906E4  , 0x81FFE0BA,0xBFB0BE14  , 0x21266264,0x3FDE5BC2  , 0xF9B9F933,0x3FC7B7A7  , 0xF27F5703,0xBF21BC5B  , 0x7F570147,0xBF6E19C1  , 0x2012517B,0x3F711D91  , 0xE7F11A06,0x3F92DC76  , 0x22741F5E,0xBFA659EC  , 0x1E4A67F8,0xBFB36454  , 0x7A44237A,0x3FDDAF43  , 0x50E8FCDD,0x3FCC30E6  , 0x608437F2,0x3F2E4E5D  , 0x726A6C31,0xBF6DDFB5  , 0xA85F82FD,0x3F646C80  , 0x48DEF895,0x3F942A3D  , 0xE4F8CD30,0xBFA35CDD  , 0x13C18F0E,0xBFB5C867  , 0xF7983BCD,0x3FDCE5C1  , 0x7FBF839F,0x3FD05532  , 0x119F094B,0x3F4210B5  , 0x8EFECF71,0xBF6C124D  , 0x3185DCF8,0x3F4A6FCF  , 0xEDF3A885,0x3F94D467  , 0x930ED4CA,0xBFA01C65  , 0x2AC80FB0,0xBFB7E370  , 0x34654049,0x3FDBFE37  , 0x4424076E,0x3FD2955E  , 0xBA559529,0x3F4A49F8  , 0x31B75FDA,0xBF68CDF1  , 0x14D26590,0xBF4A93C7  , 0x6AF6CAB6,0x3F94D25B  , 0xB75BA5BF,0xBF99458A  , 0x12696EDF,0xBFB9AEAA  , 0xA91CEA68,0x3FDAF5DD  , 0x9699F845,0x3FD4DEC1  , 0xEE35983C,0x3F4FA123  , 0xE301D0E5,0xBF643033  , 0x4AC29E52,0xBF62D9A1  , 0xBB319E09,0x3F94178C  , 0xF6F1018B,0xBF91E07C  , 0xEA4F769E,0xBFBB2392  , 0xDC89EE44,0x3FD9C4BC  , 0xBD38B5A3,0x3FD73F1C  , 0xD3C2B1B1,0x3F50B582  , 0x4EE33BC4,0xBF5CEAF2  , 0xC90264E8,0xBF6D3978  , 0x427214BC,0x3F9293BF  , 0xDC802AFB,0xBF844C42  , 0xCD0F501F,0xBFBC2EB4  , 0x5FFBBBDD,0x3FD86351  , 0xD956D26B,0x3FD9BEF4  , 0x5B642B12,0x3F4F8CB7  , 0xA2063374,0xBF5131A6  , 0x9F7C81CB,0xBF7223E2  , 0xFAFED176,0x3F9076CE  , 0xCE596526,0xBF67B884  , 0xDF17107A,0xBFBCAE0F  , 0x08913E4C,0x3FD6EE7A  , 0xB81BC92A,0x3FDC2A8C  , 0x8AE75B8D,0x3F4B5330  , 0x2A4680C9,0xBF3C6E8D  , 0x41A2E5D9,0xBF73E54F  , 0xA7CF5CCE,0x3F8C449A  , 0x8333EC93,0x3F680330  , 0x10EB8204,0xBFBCAC4E  , 0x07934388,0x3FD5888E  , 0x8F165FE2,0x3FDE54D4  , 0x8F968428,0x3F45F5B3  , 0xCB342EEA,0x3F10E670  , 0xA68805B7,0xBF744D10  , 0xCF61E493,0x3F878062  , 0xC76A2D9E,0x3F7F8FF9  , 0x82083A3A,0xBFBC4839  , 0xC5C30169,0x3FD43011  , 0x5D5C6C1C,0x3FE0267C  , 0x2A5690D1,0x3F4036D8  , 0x80C59B12,0x3F3D612C  , 0xBF8DC953,0xBF73AEEB  , 0x345D6F1C,0x3F82C79F  , 0x49544C80,0x3F87BC65  , 0x8D135423,0xBFBB9459  , 0x744F7252,0x3FD2DF48  , 0xE7AB5DA1,0x3FE111BE  , 0x78216413,0x3F354F7C  , 0xD590DB23,0x3F479CAE  , 0x78079689,0xBF724AB2  , 0xEA12613F,0x3F7C7F88  , 0x0DC95F35,0x3F8E0342  , 0x84B2295E,0xBFBA9D7A  , 0xEFA9ED55,0x3FD194ED  , 0x0F2F3CE8,0x3FE1EFC2  , 0xC2AEBB14,0x3F26BCE5  , 0x503622E0,0x3F4D2049  , 0xEC7B4B42,0xBF705844  , 0x4C0429D7,0x3F740E98  , 0x30D57DF2,0x3F915C5A  , 0x880C4FB5,0xBFB96DE1  , 0x864ECCD6,0x3FD050AD  , 0x07EAAB7B,0x3FE2C2C5  , 0xF784C8FE,0x3F08EBFB  , 0x70E2EA3B,0x3F4F9BDE  , 0x41A4E40B,0xBF6C1299  , 0xAFD46D7C,0x3F68D616  , 0x261DD86C,0x3F92FB81  , 0x784332A0,0xBFB80E1B  , 0x4B6B3601,0x3FCE24B5  , 0xBF27EB23,0x3FE38C84  , 0xC82F4AEC,0xBF098952  , 0xF9674932,0x3F4F85F8  , 0x3BD91643,0xBF6711E5  , 0xE5E56EEF,0x3F56D67B  , 0xBF3B618C,0x3F93EC12  , 0x54149AEC,0xBFB684F7  , 0x5FE1D97D,0x3FCBB2E6  , 0xE7E50F06,0x3FE44EAD  , 0x977EC072,0xBF1E039C  , 0x276BA9F0,0x3F4D5CC4  , 0x84C95F2C,0xBF61F40D  , 0x71287AF9,0x3E95635A  , 0x25C479C6,0x3F943A2B  , 0x92B45D9B,0xBFB4D625  , 0xD79C92BF,0x3FC9482B  , 0x0082E6BC,0x3FE50B92  , 0xD2877B84,0xBF23D3C6  , 0x96EF8614,0x3F498E1F  , 0x10C34108,0xBF59C99F  , 0x7BBE9CC4,0xBF52CDE4  , 0xAB4AD496,0x3F93EC7A  , 0x3C35DAAB,0xBFB2FD29  , 0x57D229D5,0x3FC6D833  , 0xAE19F884,0x3FE5C7F3  , 0x8FABEA19,0xBF25120A  , 0xCC0A707C,0x3F44A4B9  , 0x16D8A7F7,0xBF50653B  , 0x16319F9D,0xBF607BE4  , 0x32543A39,0x3F93079B  , 0xDE309EE4,0xBFB101DF  , 0x3021BD3A,0x3FC468B5  , 0xEF95767F,0x3FE68322  , 0xE7972256,0xBF239543  , 0x98726489,0x3F3F548F  , 0x119720D2,0xBF41B2B6  , 0xF79A370D,0xBF64CDE7  , 0xB5A317FC,0x3F91B872  , 0xA87B29F8,0xBFAE2EEA  , 0xA279BE28,0x3FC22EC1  , 0xC5538567,0x3FE72E5E  , 0x8BD2EA2A,0xBF20CC9B  , 0xE9B283DF,0x3F36C1D3  , 0xC113FFC3,0xBF2B7306  , 0xDC203311,0xBF66D0BF  , 0xA3753147,0x3F903F52  , 0xB37F0EEC,0xBFAAC360  , 0x8138F061,0x3FC0463A  , 0x082C7B74,0x3FE7C222  , 0xD7D0CC50,0xBF1B4605  , 0xCF9BB85E,0x3F2F767F  , 0xA1F6FC72,0x3EF63CD5  , 0x187882A9,0xBF674910  , 0xA2BF2921,0x3F8D7143  , 0xDA73E984,0xBFA7B36C  , 0x9602EFE8,0x3FBD39CC  , 0x00C70C96,0x3FE84449  , 0xB4C2A3CC,0xBF151924  , 0x50D36417,0x3F244571  , 0xA3AA058C,0x3F272050  , 0x8F008589,0xBF66B7F6  , 0xC468BE6E,0x3F8A62F3  , 0xD5D152A9,0xBFA4EDB4  , 0x58BE5A2F,0x3FBA4606  , 0x27B94E4D,0x3FE8B9C5  , 0xDCFD7897,0xBF0F1D5E  , 0x99224A1F,0x3F1753B8  , 0xF1C84C77,0x3F31EB93  , 0x1DFAC7C8,0xBF6573E6  , 0x4A232891,0x3F876793  , 0xA53664C2,0xBFA269FF  , 0x1B038C26,0x3FB7A055  , 0x9B56CB0B,0x3FE9253A  , 0xF110A2FA,0xBF05C1BC  , 0x76E6D768,0x3F053C95  , 0xA05FAB01,0x3F355A9F  , 0x49DD263E,0xBF63BC96  , 0x36864EA6,0x3F848DAB  , 0x075A3FE6,0xBFA022FF  , 0xB94F8009,0x3FB53DAB  , 0x1263C2D4,0x3FE98861  , 0x80AC54D2,0x403C8AA8  , 0x4E465BD3,0x401CA7D1  , 0x2DF28428,0xC01B567F  , 0x05EB1D91,0x3FEF73C4  , 0x3629DF1B,0x3FEE2D32  , 0xE7F35D8D,0xBFCA7C99  , 0x5EA4302D,0xBFE54B30  , 0x2C6AEF4C,0x3FE9EA7B  , 0xF1FA6696,0x40498581  , 0x02864722,0x40000260  , 0xAEE03C5A,0xC01D8518  , 0x2E44E73D,0x3FFA722B  , 0xE5AC3F66,0x3FEB0721  , 0x799C2B4F,0xBFD078E1  , 0x8A4B2D2F,0xBFE503D1  , 0xA73228FC,0x3FEA4FEB  , 0x8E20B649,0x4053169A  , 0x50DE59EF,0xC018E2E3  , 0x08AAED6B,0xC01CB810  , 0xACDCDBE8,0x4002A7C7  , 0x21F3531C,0x3FE650D4  , 0xA27ACEF0,0xBFD3385B  , 0x083BA787,0xBFE4AF43  , 0xFDE4C245,0x3FEAB27C  , 0x77B5B038,0x4058BAD8  , 0xDDFC6688,0xC031E51A  , 0xCC77AFF9,0xC01761B4  , 0xD1B77D93,0x4007A7FA  , 0x6D3C245A,0x3FDFCD45  , 0xBE7D243F,0xBFD5660D  , 0x71D87E72,0xBFE44CD3  , 0x34B88070,0x3FEB1588  , 0x6304F910,0x405A2C77  , 0xAE773C04,0xC0402AE6  , 0x48727A6E,0xC006F3CD  , 0x1CA23888,0x400B3933  , 0xA1051F98,0x3FCF18C6  , 0x954942F9,0xBFD6D12E  , 0x0CB98088,0xBFE3DC49  , 0x42A92EC6,0x3FEB7B64  , 0xE538E3BE,0x405263F6  , 0xE0F2D10E,0xC04630B6  , 0xB4336FE6,0x3FF6DB19  , 0x3C5A903D,0x400BD6F9  , 0x34E735E1,0xBF8CF3E2  , 0x0B71B4BF,0xBFD739A3  , 0xFF5A06AC,0xBFE36EE9  , 0x5511B629,0x3FEBD86D  , 0x3911DD9B,0x3FFD98ED  , 0x8B57299D,0xC0488741  , 0x5B895C73,0x4017FF1A  , 0xD63858D1,0x40097AE6  , 0xCF667355,0xBFCD72AB  , 0x0BB5AB0C,0xBFD6D811  , 0x583F32C1,0xBFE31009  , 0xD57AEDAC,0x3FEC2783  , 0xF9CAB0EA,0xC05ADEBC  , 0x090DF9FA,0xC045E541  , 0xE39578B9,0x40249CFA  , 0xD24CD4AC,0x400486DD  , 0xD70ECE9A,0xBFD9F4E3  , 0x64CFD204,0xBFD5E99C  , 0x08C1714D,0xBFE2B946  , 0x51DEBC5D,0x3FEC709F  , 0x16C46753,0xC06D8698  , 0x1B6285B4,0xC03A0BEF  , 0x504A9301,0x402B064B  , 0xC2F1572B,0x3FFAD199  , 0x4F4F809D,0xBFE1072A  , 0x63ADEFCA,0xBFD491DC  , 0xF0A254A3,0xBFE268CC  , 0x6B80B698,0x3FECB6DB  , 0x9530F7FE,0xC07541F1  , 0xD008BC59,0x401697CC  , 0xA11B7A93,0x402D1A27  , 0x27960542,0x3FE2760A  , 0x711128B3,0xBFE34308  , 0x8F13A4AE,0xBFD2E065  , 0x320F6810,0xBFE21AFB  , 0x594D00CA,0x3FECFED2  , 0xE6A43E07,0xC074A3EF  , 0x32182B09,0x4044C3A5  , 0x37310ACD,0x4028E9BA  , 0xAEFBF852,0xBFDC16CA  , 0x402090C5,0xBFE35E2A  , 0xBA320B68,0xBFD12717  , 0xB50847A8,0xBFE1D6F1  , 0x582ABD2B,0x3FED42B0  , 0x8A3F187B,0xC0666B8B  , 0x7393F019,0x405066A5  , 0x8B4CC8DD,0x40206C7F  , 0xA7857B43,0xBFF1DA5E  , 0x692A4CFA,0xBFE20BC6  , 0x9ACFB8E5,0xBFCF64E8  , 0xA1A5D894,0xBFE1A0B6  , 0x3167F6AA,0x3FED7D44  , 0x2CF7A103,0x405242DF  , 0xDA5A0907,0x4051AB15  , 0x785ED052,0x400827AC  , 0xDDDDF51A,0xBFF76D1A  , 0x970A4E63,0xBFDFEF13  , 0x3FA9A312,0xBFCCDEC0  , 0x006A5522,0xBFE1712E  , 0xF4F8DC07,0x3FEDB4A1  , 0x2E6BF8F2,0x4074BC5F  , 0x79975010,0x4049AF0D  , 0x64D71854,0xBFFEEA94  , 0xD4197A59,0xBFF7DC62  , 0xC29A1E87,0xBFDAE7BD  , 0xAEAB743C,0xBFCA90BE  , 0x3FF32E71,0xBFE142EC  , 0xC67D22FC,0x3FEDEE9C  , 0x587B3BA5,0x4078D02F  , 0xAD604C01,0x40314BA2  , 0xCD369A69,0xC0125083  , 0x75B3EC46,0xBFF458C3  , 0x0C7B8BC4,0xBFD6638D  , 0xC3F473CE,0xBFC8B34B  , 0x46331986,0xBFE1197D  , 0x89695018,0x3FEE2636  , 0xB2B2A0FC,0x406E248F  , 0x6225A085,0xC022952F  , 0x6A4BE80D,0xC013179F  , 0x8696DC60,0xBFEFDF3F  , 0x3E9E490F,0xBFD312A0  , 0xBC23212E,0xBFC748F7  , 0x35F3D287,0xBFE0F675  , 0xFE0E0928,0x3FEE57FB  , 0x6BBEC12A,0x40061246  , 0x3C7D07AB,0xC0335878  , 0xA2416988,0xC00C9637  , 0x562DAF8B,0xBFE787D4  , 0xEDA45768,0xBFD05D3E  , 0xC4D71090,0xBFC5FB33  , 0x38B24767,0xBFE0D2D1  , 0x8ECEDAFA,0x3FEE8D39  , 0x6B61B1D8,0xC056C27C  , 0xD45DC391,0xC02C4E66  , 0xAE40968B,0xC0022780  , 0x24690DA4,0xBFE1CBFE  , 0xE24920A7,0xBFCCAAB1  , 0x0EEE1581,0xBFC4D764  , 0x47BE2FCB,0xBFE0B0CF  , 0x1BA75933,0x3FEEC27C  , 0x123991F9,0xC049C848  , 0x955A2D21,0xC01C94C7  , 0xBD2C64D3,0xBFF71D05  , 0x84DFAA2E,0xBFDBDA50  , 0x42B0C3EA,0xBFC94E0C  , 0x01DAC3C5,0xBFC3C300  , 0xE5AE39C8,0xBFE08E15  , 0xD3CBADBB,0x3FEEFB60  , 0x2044B3E4,0xC0330A61  , 0x35F4BEB9,0xC00E08AD  , 0xECFA801B,0xBFEF507B  , 0x1700BEC7,0xBFD61C35  , 0x1A34E5CD,0xBFC64E28  , 0xE23C8AC1,0xBFC2AF36  , 0x794DBEC5,0xBFE068E6  , 0x35283C60,0x3FEF3B2E  , 0xCB5A5385,0xC021DDCF  , 0xCF11DAEF,0xC001CE67  , 0x13F7CF0B,0xBFE610B1  , 0xBCCA5758,0xBFD1B819  , 0x419852FE,0xBFC3A94A  , 0x7CB6C479,0xBFC1A2AA  , 0x1297CB31,0xBFE04219  , 0x80CD04D9,0x3FEF8105  , 0xB6D973A3,0xC011D695  , 0x6B705912,0xBFF568E0  , 0xBFEB1A3D,0xBFDEE782  , 0xA92BD23A,0xBFCC0F73  , 0x8981B949,0xBFC124BE  , 0x024863BE,0xBFC08948  , 0xBE091854,0xBFE01678  , 0x1FB9EB7B,0x3FEFD3AB   };
ALIGN_VEC const int32_t fun3[(numTableElements)*2] = { 0xE073A0F2,0x3F422935  , 0x4F89EB4C,0xBF99AFBB  , 0x0B89F655,0x3E927415  , 0xA4C88920,0x3FBAAAAA  , 0x68E6F85B,0x3D73356F  , 0x00000000,0xBFD80000  , 0x00000000,0x00000000  , 0x00000000,0x3FF00000  , 0xBF3D7948,0x3F6FE934  , 0xDA1CF422,0xBF985B9B  , 0xFC45B3F2,0xBF8C2ECE  , 0x45BEE47D,0x3FB9D0FD  , 0xA88D1A73,0x3FA50BD1  , 0x51607D76,0xBFD793F8  , 0x43BD3D33,0xBFB6D706  , 0xDFEF305D,0x3FEFC585  , 0x0468D91D,0x3F7D3C37  , 0xBEE3B845,0xBF94D4B9  , 0x1E0C8555,0xBF9A681F  , 0xB1973F7E,0x3FB773C8  , 0x2DA4DE44,0x3FB414BD  , 0x9539AB89,0xBFD663F2  , 0xB074432E,0xBFC61927  , 0x8435DF66,0x3FEF1F68  , 0x8873749F,0x3F832C69  , 0xFB9D9A7C,0xBF8F96E8  , 0x5C5F4845,0xBFA1F711  , 0x915C78A8,0x3FB3FA5D  , 0xEE091E09,0x3FBC2044  , 0x79D8AC53,0xBFD49A8F  , 0x58B86C16,0xBFCFA384  , 0xE2561BA3,0x3FEE20FB  , 0x096A2092,0x3F85825D  , 0x5460D2DA,0xBF839ADC  , 0xFBB15EE2,0xBFA54008  , 0x79008DC9,0x3FAF506F  , 0xB5A1FCDF,0x3FC15324  , 0x41E56688,0xBFD24DB0  , 0xBCA55798,0xBFD41654  , 0xB8D0AD7B,0x3FECD0C7  , 0xB39A0C4A,0x3F859345  , 0x09487D87,0xBF6B6BC4  , 0x8659A474,0xBFA6F2F1  , 0xBAC756E9,0x3FA586E4  , 0x5E333DCE,0x3FC3C0D1  , 0xDA85D90A,0xBFCF2520  , 0x229BB44A,0xBFD7D246  , 0x5B0C0E88,0x3FEB338B  , 0x1B690144,0x3F838542  , 0x21800B74,0x3F65EE96  , 0xB8F45F06,0xBFA70619  , 0xA56926FB,0x3F966341  , 0x77B3EE12,0x3FC546D7  , 0xDEB6856E,0xBFC9023F  , 0x98A94747,0xBFDAF66E  , 0x6149F0AA,0x3FE94E44  , 0x9D010D57,0x3F7F684E  , 0x2E095ABA,0x3F804FB9  , 0xE2064440,0xBFA58A03  , 0x2CFDCE5C,0x3F5DC0E6  , 0xA1E616E9,0x3FC5D993  , 0xB046FE0A,0xBFC265BA  , 0x7EFD0DA6,0xBFDD7341  , 0x0D15FE15,0x3FE725A3  , 0xBC2F470D,0x3F755144  , 0xADC93D77,0x3F88B001  , 0xB6ED9C5A,0xBFA2A935  , 0xC8F677C0,0xBF914FE3  , 0x66E8716B,0x3FC574E6  , 0x275982E7,0xBFB70ABC  , 0xBBB0AC16,0xBFDF3955  , 0x08C66B91,0x3FE4BDEB  , 0x463CF587,0x3F641CE9  , 0x51E6684F,0x3F8DE64F  , 0xC0E808CE,0xBF9D4628  , 0xF426752C,0xBFA0FFC6  , 0xB9EB6CC9,0x3FC41AE5  , 0x3DA9E269,0xBFA252AD  , 0x03A52120,0xBFE01CAE  , 0x141983D0,0x3FE218A8  , 0x98EBDEC9,0xBF30C33D  , 0xD8D60C68,0x3F8F75C8  , 0x8DC36E7A,0xBF937B67  , 0x0ECD0D5D,0xBFA799CE  , 0x99770CBB,0x3FC1CB1E  , 0x7C9165FC,0x3F922D8C  , 0x76F4A39F,0xBFE02F72  , 0x38971612,0x3FDE5B8B  , 0xE266E253,0xBF64BF63  , 0xBDC42319,0x3F8D0EF9  , 0x63004F6B,0xBF819EFF  , 0xD9070FEA,0xBFABCEFD  , 0xEF422586,0x3FBD1DF6  , 0x6BDF5443,0x3FB1796C  , 0x1A6CB1D1,0xBFDF8824  , 0xC178B6C7,0x3FD7F94F  , 0x3FE974C2,0xBF6FDE18  , 0x7CA28C27,0x3F878A38  , 0x1697ECFC,0x3F45B993  , 0x2D193C9A,0xBFAD015A  , 0x46A8160A,0x3FB5CA72  , 0xA2C8631A,0x3FBBE625  , 0x29DBDF87,0xBFDDC5AF  , 0x867DA8FE,0x3FD1B08E  , 0x49EC7D0A,0xBF719EEA  , 0xCDFDF958,0x3F80E72A  , 0x3F97EAA5,0x3F7E5E0C  , 0x51B47A7F,0xBFABBDE3  , 0x7D7C627F,0x3FADAEFA  , 0x74153067,0x3FC18313  , 0xA6979309,0xBFDB752E  , 0x3C8D961C,0x3FC8372C  , 0x12F29DB7,0xBF70A189  , 0x61B180D3,0x3F74BD52  , 0x57BAADC8,0x3F882C3A  , 0xEE0079ED,0xBFA8E766  , 0x91D0104A,0x3FA13530  , 0x4D5FC31A,0x3FC3B706  , 0x9DA15CD1,0xBFD8CED1  , 0xD865A1EF,0x3FBCAC80  , 0x20D4FBCE,0xBF6BFB13  , 0xCD66F3D2,0x3F624671  , 0x6CDAF790,0x3F8D08B5  , 0x0AE4DC40,0xBFA51A55  , 0x193DD836,0x3F896BA9  , 0x1F7C4E66,0x3FC4CF4E  , 0xF8E0667E,0xBFD5EF63  , 0x7F57C1B0,0x3FA621A7  , 0xF9DF789B,0xBF650F68  , 0xD506E378,0xBF0C6619  , 0xA56B752D,0x3F8E7056  , 0x2B6037FB,0xBFA0D1FE  , 0xB2E5983C,0xBF756979  , 0xF8EFFF5A,0x3FC4F7F9  , 0xEFF5059B,0xBFD2F14A  , 0x96930DDE,0xBF91FE84  , 0x63619FF4,0xBF5BA5EC  , 0xFCD60016,0xBF5BFB0A  , 0xFCEEB034,0x3F8D1F57  , 0x68F67F96,0xBF98E459  , 0x8CF2EE04,0xBF939313  , 0x6303161B,0x3FC45855  , 0x93AA8D8F,0xBFCFD6BF  , 0xA563E965,0xBFB20F67  , 0x615F81BD,0xBF4CF037  , 0x54CC9460,0xBF665E21  , 0xAA999E7F,0x3F89D755  , 0x79267C0E,0xBF909259  , 0xB70F996B,0xBF9DF29C  , 0xDE01BF11,0x3FC31569  , 0x0DE638D6,0xBFC9E233  , 0xD00BD4E4,0xBFBDA575  , 0x4D56C295,0xBF2E5696  , 0x1BAEF4CC,0xBF6A1458  , 0x97C3444D,0x3F85513B  , 0xFFC5A14C,0xBF8242B1  , 0x9D04A6B1,0xBFA25074  , 0x1739C8EA,0x3FC151E0  , 0xB980F1E9,0xBFC424CE  , 0x4C775520,0xBFC3A4D3  , 0xBD1F62B8,0x3F2E8DAE  , 0x19B73B7E,0xBF69EF29  , 0x324FE1A4,0x3F802EF1  , 0x8B2B851B,0xBF66E1FF  , 0xBA1680C0,0xBFA3F1F9  , 0x94798A32,0x3FBE578C  , 0xBB8F0191,0xBFBD6942  , 0x5C73714B,0xBFC783F8  , 0xA5C85BD8,0x3F409B1A  , 0x17599683,0xBF66D1A8  , 0xD30D5D81,0x3F75D648  , 0x13ACD78D,0x3F60C3CC  , 0x57410651,0xBFA4034A  , 0x577D8DC2,0x3FB96B63  , 0x3790F0ED,0xBFB32BE3  , 0x0887B593,0xBFCA7882  , 0xC2223F31,0x3F43A079  , 0xB3F461CB,0xBF61C8E5  , 0x46A67721,0x3F685DA7  , 0xFE02B666,0x3F760952  , 0xEC855A2D,0xBFA2ABAE  , 0x5AE35DEF,0x3FB42816  , 0xED67BEA6,0xBFA3DB91  , 0xD9220AA9,0xBFCC6A96  , 0xB43414EB,0x3F4237DB  , 0xEB2987DA,0xBF58EAF3  , 0x02A721D7,0x3F5369FC  , 0x16C7114E,0x3F7CF373  , 0x16B7F0D0,0xBFA06A27  , 0x99637298,0x3FAE8B6D  , 0xC02215FB,0xBF84965F  , 0xFD94A65B,0xBFCD42B5  , 0x78C63550,0x3F3DB8B3  , 0x2C364926,0xBF4FFD48  , 0x042F6740,0x3EF6EF94  , 0xBEF7C830,0x3F7ECCBA  , 0x11EA84FB,0xBF9BC408  , 0x3C439C6C,0x3FA6688F  , 0x9451B580,0x3F85DAD1  , 0xB65C23BA,0xBFCD3B4D  , 0x534A05E6,0x3F363626  , 0x8237C933,0xBF424CE1  , 0x84178C85,0xBF4626F8  , 0xC1EF032D,0x3F7DA2D1  , 0x4322402F,0xBF96C166  , 0xBFE4E5B1,0x3F9F816D  , 0xD412E9AA,0x3F99EE94  , 0xB8600D07,0xBFCC9C1D  , 0x9A85E928,0x3F2EA0CD  , 0x41A11E89,0xBF30D113  , 0xFDC7CA55,0xBF511CBE  , 0x8977D160,0x3F7AC290  , 0xBE270FEA,0xBF921208  , 0xEF4F675C,0x3F94B63D  , 0x05D4051D,0x3FA21CAE  , 0xF5554E9F,0xBFCB91A4  , 0x8BE07323,0x3F234715  , 0xADB1B900,0xBF0C017D  , 0x3CBC523F,0xBF536053  , 0xE4AD6429,0x3F77050F  , 0x9447BB68,0xBF8BBE61  , 0xC0E541B1,0x3F8843A1  , 0x7B8E6487,0x3FA564A1  , 0xF9422DA5,0xBFCA3A78  , 0x7F6EF6C1,0x3F156269  , 0x071F7068,0x3F1299A6  , 0x3C19F61D,0xBF5321F0  , 0x6009453A,0x3F72FDFD  , 0xCDB19CE0,0xBF847BCC  , 0x1962B9D8,0x3F75FB5B  , 0x5B80586C,0x3FA72FBF  , 0x866767AA,0xBFC8ADEC  , 0xAD3C9E2B,0x40883B65  , 0x20196F15,0x40734EF7  , 0x1D62B4D7,0xC06B6A6E  , 0x1C4C1073,0x4043CA24  , 0xFABA4372,0x402DDC2C  , 0x01E8882F,0xC0208F96  , 0xDB507568,0xBFF0F2CC  , 0x3FDC3C03,0x3FF9B5DC  , 0xD6D22921,0x409CF9A6  , 0x2A1432D7,0x405D4CAE  , 0xF9B45616,0xC06F25FC  , 0xE5DF9901,0x40508893  , 0x9D710065,0x402403C2  , 0xA2B2FF7E,0xC02275C0  , 0xB7D650B8,0xBFE21A0E  , 0xE6DAA902,0x3FFA332F  , 0x7F235FF8,0x40A9C2C3  , 0x89487902,0xC07038D7  , 0x899DDC67,0xC06E5025  , 0x5F9BC1FC,0x40577445  , 0x85FE42C4,0x4004F3DB  , 0xA0D01ABB,0xC0236C8C  , 0xD17FF1FD,0xBFA3BF50  , 0xE4801830,0x3FFA6138  , 0x8026D303,0x40B30750  , 0x8F385BF0,0xC08B7753  , 0x1B411779,0xC065457C  , 0x409CF4F3,0x405D7D69  , 0x7FB1FF29,0xC01DC16D  , 0xA8072DC8,0xC02316C5  , 0x4A0C6072,0x3FE05414  , 0xA5FDE557,0x3FFA3CA1  , 0x5EADEC55,0x40B624AD  , 0xDC1480A4,0xC09B1FBB  , 0x31BD3C2F,0x40230191  , 0x447B3F54,0x40601641  , 0x815822D9,0xC033D503  , 0x072697D4,0xC020F12C  , 0x401E7A18,0x3FF0CF06  , 0x458447D7,0x3FF9BD1B  , 0xD628D3A6,0x40AE165F  , 0x9D7742F2,0xC0A36A83  , 0xC67566BB,0x4071DDBA  , 0xB8C066D2,0x405C4DEE  , 0x08847E0A,0xC03F4170  , 0x152BC22F,0xC01A4A1E  , 0x8267C3AB,0x3FF78CB7  , 0x36EDBDCC,0x3FF8FCAB  , 0xFD79224D,0xC098DA95  , 0x90A4952C,0xC0A4EAF5  , 0xDEF3CB4D,0x40823815  , 0xB36D129F,0x4051E421  , 0x8A850EEB,0xC0436E6A  , 0x57EE2C64,0xC01136E3  , 0x384DE646,0x3FFBC555  , 0xEC30B836,0x3FF82897  , 0x54B83D84,0xC0C553DB  , 0x584550F5,0xC09EA297  , 0x63BCA1AD,0x408A3A5D  , 0x3AA164E7,0x401A006E  , 0xA454288E,0xC044FAEB  , 0x37E4AA65,0xBFFD5D6A  , 0xA933F0C7,0x3FFE0267  , 0x48CCBFD5,0x3FF747D7  , 0xB42096E3,0xC0D5E9E1  , 0x8C45AE94,0x401FFA63  , 0x23F1A85E,0x408DC9D1  , 0x1D8061ED,0xC0529E58  , 0xFFB30832,0xC043C19A  , 0xF4251101,0x3FE34621  , 0xCAD8B408,0x3FFE702D  , 0x009C093F,0x3FF66210  , 0x9BA0E560,0xC0DD80C6  , 0xA14DA8D2,0x40AA2EFC  , 0x0559E794,0x40886E27  , 0x8EB501C4,0xC063AD92  , 0x82808CC4,0xC03E7C08  , 0xE64D87A1,0x40065422  , 0x55AF22F8,0x3FFD2656  , 0xA539396F,0x3FF57617  , 0x9077AD4B,0xC0D54B9F  , 0xB7A04EFD,0x40B9ED7C  , 0xB90D1DDD,0x40700FA1  , 0x6F46B69F,0xC069BE42  , 0x2BD9DA1F,0xC030CBF0  , 0xE8DD88E6,0x4010D0C7  , 0xD397BD2A,0x3FFAA011  , 0x0A44E8E5,0x3FF4A2D2  , 0x9AD6D4FF,0x40B7C16A  , 0xE19277CF,0x40BDC13A  , 0x8387F4CA,0xC079A906  , 0x55DDAD03,0xC069131F  , 0x21620EE4,0xC00B3688  , 0xFEEEDA5C,0x4012E516  , 0xFAFA7738,0x3FF7D315  , 0xE5105930,0x3FF3FBFB  , 0xE74A3E2B,0x40E5A031  , 0x93C8FBAC,0x40B418E9  , 0xB5BC3B0F,0xC08EFBFA  , 0x3C51E823,0xC0626CD0  , 0x887B5421,0x401E3600  , 0x0D8D8D93,0x40126E58  , 0x2DBF9136,0x3FF5090B  , 0xC168BA5D,0x3FF36E5D  , 0xEF613FFA,0x40F05CEE  , 0xED059F8A,0xC08F82D9  , 0xFB372C87,0xC092C2BD  , 0x2E495900,0xC04CE9CA  , 0xA5F81AD8,0x402CAE7C  , 0x054F0009,0x40100ACA  , 0xBF5F7CCE,0x3FF2511A  , 0x0A6F9204,0x3FF2EB13  , 0xC6E49F3B,0x40E1F257  , 0xC8B52ACA,0xC0BA666A  , 0x5F762256,0xC08A03E4  , 0xB191451E,0x403694B5  , 0x380BF8F5,0x402E9C8F  , 0x8CE74C63,0x4009EA27  , 0x32C4BA87,0x3FF01D5C  , 0x73DE1075,0x3FF27BE4  , 0xAD579815,0xC0D854A4  , 0xC954FB58,0xC0BCB300  , 0x792E8341,0xC06C66DD  , 0x9A598FD8,0x404D92F3  , 0xF0209937,0x40298C01  , 0x8F0A6615,0x4004B8E2  , 0x79D09E46,0x3FED0BB1  , 0x40B99B88,0x3FF22287  , 0xFAC6B20A,0xC0EB447C  , 0xF4F88995,0xC0A58F83  , 0xFA8E54A1,0x406D0F69  , 0x77D6B163,0x404C36AE  , 0xB2A684ED,0x40221499  , 0xFC5F5116,0x40006E8A  , 0x79BC90FD,0x3FEA51C6  , 0x5C35CE39,0x3FF1CB72  , 0x8EE4230F,0xC0D15D9E  , 0x07876BAA,0x40935753  , 0x120A3EBF,0x4070B909  , 0xE7903B92,0x4041CC09  , 0xB090572F,0x4018B0E4  , 0xD407BACE,0x3FFAE826  , 0xB973DFA1,0x3FE81B76  , 0x9117E689,0x3FF17B6C  , 0x02AFCBED,0x40C2F886  , 0x1CB56AC3,0x409247A2  , 0xCB05E84E,0x4060425B  , 0x2D08B265,0x4033C5E9  , 0x915140E0,0x40118AE9  , 0x2B50FDBD,0x3FF676FC  , 0xCDFBA82B,0x3FE6231A  , 0x63B4B6D9,0x3FF12C62  , 0x3FCBFB5D,0x40A83CE4  , 0x5ACD1DD3,0x4076DFFC  , 0xC92EFEAB,0x404CB7A4  , 0xDAEE5D2C,0x4027D4AC  , 0x5664303A,0x4009D35E  , 0x74DF6594,0x3FF2D3E1  , 0x8F9F7DA7,0x3FE445B7  , 0xAF0E73EC,0x3FF0DA67  , 0x2883D401,0x408A6228  , 0x2EE36F20,0x40625D08  , 0xAD5637AE,0x403E72E7  , 0xB5EEAC95,0x401EDB3F  , 0x6280CC76,0x40036A71  , 0x63B3825C,0x3FEFABFE  , 0x168EC541,0x3FE28AE0  , 0x89ED7F2E,0x3FF08786  , 0x28C30804,0x407272A8  , 0x97DD0C56,0x4050646D  , 0xBC6774C5,0x4030ADF1  , 0x584D91E9,0x4014019C  , 0xB15432BB,0x3FFCE4F2  , 0x40E9A1E5,0x3FEA5230  , 0x5E401F40,0x3FE0D056  , 0x68B5BA4F,0x3FF02D51   };
const int fun3_numextra = 1;
ALIGN_VEC const int32_t fun3_extra[(fun3_numextra * numPolynomes)*2] = { 0x00000000,0x00000000  , 0xA5845284,0x3FB45F9B  , 0x6F23A7A2,0x3FC3E951  , 0xF7D21E5F,0x3FCCF5DF  , 0x566175B0,0x3FD2C928  , 0x5E40837D,0x3FD6E5FE  , 0xB70402CA,0x3FDACFF7  , 0xEEFB2FA6,0x3FDE83C4  , 0xCFA34636,0x3FE0FE81  , 0x3FEF47D5,0x3FE29C48  , 0x0863427B,0x3FE41C23  , 0x6DB815DB,0x3FE57673  , 0xEA26F262,0x3FE686CC  , 0x76276FF9,0x3FE7400D  , 0x088ABDA6,0x3FE7B405  , 0xB1648207,0x3FE7EF52  , 0xC8DF3F11,0x3FE7F8BE  , 0x50311348,0x3FE7D504  , 0x5E43BBF7,0x3FE787AF  , 0x9D9FF865,0x3FE71342  , 0xBE9B755B,0x3FE67892  , 0xA3F74140,0x3FE5B3F0  , 0xC74DB33D,0x3FE4C542  , 0x68493FE6,0x3FE3C44B  , 0x57D10DF2,0x3FE2C8AC  , 0x1105D0DD,0x3FE1D454  , 0x9D50989D,0x3FE0E5FA  , 0x39DEAF1A,0x3FDFFBB5  , 0x954F6A9B,0x3FDE3900  , 0xF7089439,0x3FDC67EC  , 0xB222835B,0x3FDA75BA  , 0x08BF378A,0x3FD88432  , 0xC61ED896,0x3FD68721  , 0x45ED138B,0x3FD4774F  , 0x10FAFED9,0x3FD29685  , 0x7299DE4E,0x3FD10274  , 0x67C68516,0x3FCF266C  , 0x232DFB78,0x3FCC735F  , 0x46F6FEE7,0x3FC9C01D  , 0x9F9A03C2,0x3FC7445C  , 0x0F241B1A,0x3FC52BC5  , 0x6B25B672,0x3FC33A10  , 0x2C98B560,0x3FC1399E  , 0xA5BCDADC,0x3FBEAB12  , 0x053DD835,0x3FBB5312  , 0x8EF4D43D,0x3FB7C949  , 0xBBFE69C2,0x3FB44864  , 0x12F37CA3,0x3FB09395  , 0x15B58C7C,0x3FA8EBF0  , 0xD7399F80,0x3FA0005D  , 0xF10D30CE,0x3F863A0B   };

void findBinAndReduceVal( double * values, int* bins, double * reducedValues, int numel) {
	double* origin = (double *) &origins[0];
	for (int k=0; k<numel; k++ ) {
		using std::numeric_limits;
		using std::abs;
		double absval = abs( values[k] );
		float testval = (float) ( (absval < numeric_limits<double>::infinity())  ? absval : 0 );
		bins[k] = binsearch<numPolynomes, int32_t *>( (int32_t * ) &tablelimits[0], *((int32_t *) &testval));
		//bins[k] = binsearch<numPolynomes, float *>( (float * ) &tablelimits[0], testval );
		reducedValues[k] = (bins[k]>=cutoffbinidx ? 1/absval : absval) - origin[ bins[k] ];
	}
}

void evaluateTables( double * * outputptrs, int ntables , double * values, int nvalues, tempspace temp) {
	double * tableptrs[3] = {(double *) &fun1[0], (double *) &fun2[0],(double *)  &fun3[0]};
	double * table3extra = (double *) &fun3_extra[0];
	using std::min;
	using std::abs;
	using std::log;
	int numElBlk = min( nvalues, MAXELPERBLOCK) ;
	double * reducedval = temp.get<double>(numElBlk);
	int * bins = temp.get<int>(numElBlk);
	// loop over all blocks:
	for (int index =0 ; index<nvalues; ) {
		int ninblock = min( nvalues - index, MAXELPERBLOCK );
		// process first part: (lookup which polynome is required and reduce offset)
		findBinAndReduceVal( values+index, bins, reducedval , ninblock);

		// Evaluate polynomials:
		for (int curindexinblock=0; ninblock>0; --ninblock, ++index, ++curindexinblock) {
			int curtableidx = bins[curindexinblock] * polyorder;
			for (int table =0; table<ntables; table++ ) {
				double tempx = reducedval[curindexinblock];
				double * curtbl =  tableptrs[table] + curtableidx ;
				double tempval = curtbl[0];
				// evaluate polynomial, loop should be unrolled.
				for (int idx = 1; idx<polyorder ; idx++ ) {
					tempval *= tempx;
					tempval += curtbl[idx];
				}
				outputptrs[table][index] = tempval;
				//outputptrs[table][index] = tempx; // DEBUG ONLY

			}
			if (bins[curindexinblock]>=cutoffbinidx) {
				// To zero table we should add log(x) in the high part.
				outputptrs[0][index] -= .5* log( abs(values[index]) ) ;
			}
			if ((ntables>=2) && (values[index]<0) ) {
				outputptrs[1][index] = -outputptrs[1][index];
			}
			if (ntables>=3) {
				outputptrs[2][index] = outputptrs[2][index]*reducedval[curindexinblock] + table3extra[ bins[curindexinblock]*fun3_numextra ];
				if (values[index]<0) {
					outputptrs[2][index] = -outputptrs[2][index];
				}
				//outputptrs[2][index] =bins[curindexinblock]; // DEBUG ONLY
				/* DEBUG:
				if (index<=numPolynomes) {
					float * tmp = (float * ) &tablelimits[0];
					outputptrs[2][index] = tmp[index];
				}
				// */
			}
		}
	}

}


void mexFunction( int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[] )
{

	/* Check for proper number of arguments. */

	if ((nrhs!=1)) {
		mexErrMsgTxt("One input required: [out ] = rice_besseli_funs_c( bx ).");
	} else if ((nlhs<1)||(nlhs>3)) {
		mexErrMsgTxt("One, two, or three outputs required.");
	}
	const mxArray * in			= prhs[0]; // N-D array, single or double.
	
	/* parse inputs */
	//in:
	mwSize ndimsIn = mxGetNumberOfDimensions( in );

	const mwSize * sizeIn = mxGetDimensions( in );
	ptrdiff_t cumszIn=1;
	for(int k=0;k<ndimsIn;k++) {
		cumszIn *= sizeIn[ k];
	};
	if ((mxGetClassID(in)!=mxDOUBLE_CLASS) || mxIsComplex(in)){
		mexErrMsgTxt("Input should be non complex double. ");
	}
	double * inR = mxGetPr(prhs[0]);

	int tempspacebytesneeded =  MAXELPERBLOCK * (sizeof(double) + sizeof( int ) );
	const int maxthreadsuse =1;
	char * tempspaceptr =NULL;
    if (tempspacebytesneeded>0) {
        tempspaceptr = (char *) mxMalloc( tempspacebytesneeded * maxthreadsuse);
    }
	tempspace tmp = tempspace(tempspaceptr, tempspacebytesneeded);
        
	/* Create output. */
	double * outR[3];
	plhs[0] = mxCreateNumericArray((int) ndimsIn, sizeIn , mxDOUBLE_CLASS, mxREAL);
	outR[0] = mxGetPr(plhs[0]);
	if (nlhs>1) {
		plhs[1] = mxCreateNumericArray((int) ndimsIn, sizeIn , mxDOUBLE_CLASS , mxREAL);
		outR[1] = mxGetPr(plhs[1]);
		if (nlhs>2) {
			plhs[2] = mxCreateNumericArray((int) ndimsIn, sizeIn , mxDOUBLE_CLASS , mxREAL);
			outR[2] = mxGetPr(plhs[2]);
		}
	}

	evaluateTables( outR, nlhs , inR, cumszIn, tmp);
 
	if (tempspacebytesneeded>0) {
		mxFree(tempspaceptr);
	}
}
